package com.atguigu.ssyx.user.controller;


import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.enums.user.Leader;
import com.atguigu.ssyx.model.product.AttrGroup;
import com.atguigu.ssyx.user.service.LeaderService;
import com.atguigu.ssyx.vo.product.AttrGroupQueryVo;
import com.atguigu.ssyx.vo.product.SkuInfoVo;
import com.atguigu.ssyx.vo.user.LeaderQueryVo;
import com.atguigu.ssyx.vo.user.LeaderVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/user/leader")
public class LeaderController {


    @Autowired
    private LeaderService leaderService;

    @ApiOperation("团长列表")
    @GetMapping("list/{page}/{limit}")
    public Result listLeader(@PathVariable Long page,
                       @PathVariable Long limit,
                       LeaderQueryVo leaderQueryVo) {
        Page<Leader> pageParam = new Page<>(page,limit);
        IPage<Leader> pageModel = leaderService.selectPageLeader(pageParam,leaderQueryVo);
        return Result.ok(pageModel);
    }


    @ApiOperation("团长待审核列表")
    @GetMapping("checkList/{page}/{limit}")
    public Result checkList(@PathVariable Long page,
                       @PathVariable Long limit,
                       LeaderQueryVo leaderQueryVo) {
        Page<Leader> pageParam = new Page<>(page,limit);
        IPage<Leader> pageModel = leaderService.selectPageCheckList(pageParam,leaderQueryVo);
        return Result.ok(pageModel);
    }


    //添加团长信息
//    u
//    method: 'post',
//    data: role
    @ApiOperation("添加团长信息")
    @PostMapping("save")
    public Result save(@RequestBody Leader leader) {
        leaderService.saveLeader(leader);
        return Result.ok(null);
    }
    @ApiOperation(value = "删除")
    @GetMapping("get/{id}")
    public Result getLeader(@PathVariable Long id) {
        Leader  leader =  leaderService.getLeader(id);
        return Result.ok(leader);
    }


    //    url: `${api_name}/update`,
//    method: 'put',
//    data: role
    @ApiOperation("修改sku")
    @PutMapping("update")
    public Result update(@RequestBody Leader leader) {
        leaderService.updateLeader(leader);
        return Result.ok(null);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        leaderService.removeById(id);
        return Result.ok(null);
    }

    @ApiOperation(value = "根据id列表删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        leaderService.removeByIds(idList);
        return Result.ok(null);
    }
}
